package com.fxc.mybatis.util;

import com.fxc.mybatis.entity.PageInfo;
import com.fxc.mybatis.entity.Stu;
import com.fxc.mybatis.mapper.StuMapper;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;
import java.util.List;

public class PageHelper<T> {

    //每页显示的数量
    private int pageNum;

    //当前页面
    private int currentPage;


    public void startPage(int currentPage, int pageNum) {
        this.currentPage = currentPage;
        this.pageNum = pageNum;
    }

    public PageInfo<T> createPageInfo(List<T> datas,List<T> currentDatas) throws Exception {
        PageInfo<T> pageInfo = new PageInfo<>();
        pageInfo.setCurrentPage(currentPage);
        int total = datas.size();
        int pages = total % pageNum == 0 ? total/pageNum : total/pageNum+1;
        pageInfo.setPages(pages);
        pageInfo.setDatas(currentDatas);
        return pageInfo;

    }


}
